package itxinhaimijijia.hierarchicaldecoupling.service.impl;

import itxinhaimijijia.hierarchicaldecoupling.dao.Impl.UserDaoImpl;
import itxinhaimijijia.hierarchicaldecoupling.dao.UserDao;
import itxinhaimijijia.hierarchicaldecoupling.projo.User;
import itxinhaimijijia.hierarchicaldecoupling.service.UserService;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

public class UserServiceImpl implements UserService {

    public UserDao userDao = new UserDaoImpl();

    @Override
    public List<User> findAll() {
//        return List.of();
        List<String> lines = userDao.lindeAll();
        List<User> arrlist = lines.stream().map(item -> {
            String[] split = item.split(",");
            Integer serialNumber = Integer.parseInt(split[0]);
            String username = split[1];
            String password = split[2];
            String nickname = split[3];
            Integer age = Integer.parseInt(split[4]);
            LocalDateTime parse =
                    LocalDateTime.parse(split[5], DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            return new User(serialNumber, username, password, nickname, age, parse);
        }).toList();

        return arrlist;
    }

}
